#include <iostream>
#include <cmath>
using namespace std;
template<typename T>
class Sqrt
{
private:
    int max_iter_num;
    int iter_num;
    T a;
    double eps;
    double x0,x1;

public:
	Sqrt(T a0)
    {
    a=a0;
    max_iter_num=1e3;
    eps=1e-5;
    }
    double Solve()
    {
       x0=a/2;iter_num=0;
       cout<<"The value of initial is "<<x0<<endl;
       while(fabs(x1-x0)>=eps)
      {
       if(iter_num<=max_iter_num)
        {
           x1=x0;
           x0=(x0+a/x0)/2;
           iter_num++;
           cout<<"the result of the "<<iter_num<<"th iteration is "<<x0<<endl;
        }
       else
        {
           cout<<"The iter_num is over max_iter_num!"<<endl;break;
        }
      }
      return x0;
    }

   void set_max_iter_num(int max)
   {
       max_iter_num=max;
       cout<<"Maximum number of iterations is "<<max<<endl;
   }
   void set_eps(double Eps)
   {
       eps=Eps;
       cout<<"Accuracy of convergence is "<<Eps<<endl;
   }
   void set_x0(double X)
   {
       x0=X;
       cout<<"The value of initial is "<<X<<endl;
   }
	void set_a(double A)
   {
       a=A;
       cout<<"The value of sqrt is "<<A<<endl;
   }
};

double sec(int year,int month,int day)
{
    int temp;
    double d,s0,s;
    d=365*100+24;
    s0=24*3600;
    temp=year/100;
    if(!year%100)
    {
       if((temp%4==0)&&(month<3))d++;
       if((temp%4!=0)&&(month>=3))d++;
    }
    else
    {
       if((temp+1)%4==0)d++;
    }
    return(s0*d);
}

int main()
  {
    double x;
    int Year,Month,Day;
    cout<<"please input your birthday(1988.4.5):"<<endl;
    cout<<"year:";
    cin>>Year;
    cout<<"month:";
    cin>>Month;
    cout<<"day:";
    cin>>Day;
    if((Month>=1&&Month<=12)&&(Day>=1&&Day<=31))
      {
     //cout<<"the seconds are "<<sec(Year,Month,Day)<<endl;
       Sqrt<double> r(sec(Year,Month,Day));
       cout<<"Second of 100 years are="<<sec(Year,Month,Day)<<endl;
     //r.set_max_iter_num();    //set the max_iter_num
     //r.set_eps();	            //set the accuracy of convergence
     //r.set_x0();	            //set the value of initial
         do{
          x=r.Solve();
          cout<<"the result is "<<x<<",continue:"<<endl;
		  r.set_a(x);
         }while(x>2);
         cout<<"The final result is "<<x<<"!The iterations is over!"<<endl;
	    return 0;
       }
    else
      {
       cout<<"input error!please input again!"<<endl;
      }
  }




